package cn.new18.testactivitytask.aFragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lzy.okgo.OkGo;

import junit.framework.Test;

import cn.new18.testactivitytask.Constants.Url;
import cn.new18.testactivitytask.R;
import cn.new18.testactivitytask.base.LazyFragment;
import cn.new18.testactivitytask.base.LoadingPage;
import cn.new18.testactivitytask.bean.RecommendDetailBean;
import cn.new18.testactivitytask.bean.TestBean;
import cn.new18.testactivitytask.bean.TopBean;
import cn.new18.testactivitytask.bean.VideoBean;

/**
 * Created by RaoWei on 2016/11/22 13:23.
 */

public class FragA extends LazyFragment {

    private String Tag = "FragA";
    private static FragA mFragA;
    private TextView mText;
    private TopBean.DataBean mData;
    private TestBean.DataBean mTestData;
    private TextView mTexta;
    private TextView mTextaa;

    @Override
    protected View setContainerView() {
        View inflate = View.inflate(getContext(), R.layout.fraga, null);
        mText = (TextView) inflate.findViewById(R.id.fraga);
        mTexta = (TextView) inflate.findViewById(R.id.fragaa);
        mTextaa = (TextView) inflate.findViewById(R.id.fragaaa);
        return inflate;
    }

    public static Fragment newInstance() {
        if (mFragA == null) {
            mFragA = new FragA();
        }
        return mFragA;
    }

    @Override
    protected void OnErrorImgClick() {
        okGoRequest();
    }

    @Override
    protected void onFirstUserVisible() {
        Log.e(Tag, "first_show");
        if (mData != null) {
            return;
        }
        okGoRequest();
    }

    private void okGoRequest() {
        OkGo.get(Url.TOP)
                .execute(new LoadingViewCallBack<TopBean.DataBean>(TopBean.DataBean.class){
                    @Override
                    protected void onLoadSuccess(TopBean.DataBean dataBean) {
                        mData = dataBean;
                        Log.e(Tag, dataBean.toString());
                        mText.setText(dataBean.getBanners().get(0).getTitle());
                    }
                });
        OkGo.get("http://192.168.2.206:8080/v1/recommends/list/today/7?accessToken=WVd6L01TWUc5N0NIYlRpeHpOV09YZz09OmFyQUJsRXNZbGkwblVSTzROYjFmMGc9PQ")
                .execute(new LoadingViewCallBack<RecommendDetailBean.DataBean>(RecommendDetailBean.DataBean.class){
                    @Override
                    protected void onLoadSuccess(RecommendDetailBean.DataBean dataBean) {
                        //mTestData = dataBean;
                        //Log.e(Tag, dataBean.toString());
                        mTexta.setText("7:\n" + dataBean.toString());
                    }
                });
        OkGo.get("http://192.168.2.206:8080/v1/recommends/list/today/8?accessToken=WVd6L01TWUc5N0NIYlRpeHpOV09YZz09OmFyQUJsRXNZbGkwblVSTzROYjFmMGc9PQ")
                .execute(new LoadingViewCallBack<RecommendDetailBean.DataBean>(RecommendDetailBean.DataBean.class){
                    @Override
                    protected void onLoadSuccess(RecommendDetailBean.DataBean dataBean) {
                        //mTestData = dataBean;
                        //Log.e(Tag, dataBean.toString());
                        mTextaa.setText("8:\n" + dataBean.toString());
                    }
                });
    }

    @Override
    protected void onUserInvisible() {
        Log.e(Tag, "hide");
    }

    @Override
    protected void onUserVisible() {
        Log.e(Tag, "show");
    }
/*
    @Override
    public void onResume() {
        super.onResume();
        Log.e(Tag, "onResume");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.e(Tag, "onPause");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.e(Tag, "onDestroyView");
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        Log.e(Tag, "setUserVisibleHint, getUserVisibleHint = " + getUserVisibleHint());
    }*/
}
